// merchants/checkList/index.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    recordList:[],
    sumCutmoney: 0,
    number: 0,
    CurrentPage: 1,
    loadingMoreHidden: 1
  },

  // 获取核销记录
  getRecordList: function(){
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Coupon/GetCouponCheckList?createUid=' + app.globalData.userInfo.Uid + '&page=' + that.data.CurrentPage,
      success: function(res){
          if(res.data.Code == 0){
            let recordList = res.data.Data.List;
            let sumCutmoney = res.data.Data.Report.CutMoney;
            let number = res.data.Data.Report.TotalItems;
            if (!recordList) {
              return;
            }
            that.initDataList(recordList);
            that.setData({
              loadingMoreHidden: res.data.Data.PageModel.TotalPages,
              sumCutmoney: sumCutmoney,
              number: number
            })
          }else{
            wx.showModal({
              title: '提示',
              content: res.data.Message,
              showCancel: false
            })
          }
        }
    })
  },
  initDataList: function (list) {
    if (this.data.CurrentPage != 1) {
      var preGoods = this.data.recordList;
      list = preGoods.concat(list);
    }
    this.setData({
      recordList: list
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getRecordList();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  // 加载更多
  loadMore: function (e) {
    var that = this;
    if (that.data.loadingMoreHidden > 1 && that.data.CurrentPage < that.data.loadingMoreHidden) {
      var currPage = that.data.CurrentPage;
      that.setData({
        CurrentPage: currPage + 1
      })
      that.getRecordList();
    } else {
      return
    }
  },

})